package com.zzyl.controller.customer;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanAddDto;
import com.zzyl.dto.NursingPlanUpdateDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping("/plan")
    public ResponseResult<?> getAll(){
        return ResponseResult.success(nursingPlanService.getAll());
    }

    @PostMapping("/plan")
    public ResponseResult<?> add(@RequestBody NursingPlanAddDto dto){
        nursingPlanService.add(dto);
        return ResponseResult.success();
    }

    @GetMapping("/plan/search")
    public ResponseResult<?> search(@RequestParam(required = false) String name,
                                    @RequestParam(defaultValue = "1" ) Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer PageSize,
                                    @RequestParam(required = false) Integer status){
        return ResponseResult.success(nursingPlanService.search(name, pageNum, PageSize, status));
    }

    @GetMapping("/plan/{id}")
    public ResponseResult<?> getById(@PathVariable Integer id){
        return ResponseResult.success(nursingPlanService.getById(id));
    }

    @PutMapping("/plan/{id}")
    public ResponseResult<?> update(@RequestBody NursingPlanUpdateDto dto,@PathVariable Integer id){
        nursingPlanService.update(dto,id);
        return ResponseResult.success();
    }

    @DeleteMapping("/plan/{id}")
    public ResponseResult<?> delete(@PathVariable Integer id){
        nursingPlanService.deleteById(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult<?> updateStatus(@PathVariable("id") Integer id,@PathVariable("status") Integer status){
        nursingPlanService.updateStatus(id, status);
        return ResponseResult.success();
    }
}
